# Adds robust standard errors clustered on nation-states to non-hurdle 
# and non-zero-inflated models
# function author: Mahmood Ara at Stockholm University
# function source: the Tarzan (https://thetarzan.wordpress.com/)
cse = function(dat, fm, cluster) {
  attach(dat, warn.conflicts=F)
  library(sandwich)
  M = length(unique(cluster))
  N = length(cluster)
  K = fm$rank
  dfc = (M / (M-1)) * ((N-1) / (N-K))
  uj  = apply(estfun(fm), 2, function(x) tapply(x, cluster, sum))
  vcovCL = dfc * sandwich(fm, meat=(crossprod(uj) / N))
  coeftest(fm, vcovCL) 
}
